import type { PageType } from '../../../lib/page_handler/type'
import type { ModulePlatformConfig } from '../types'
import { BaiduPageType } from '../../../lib/page_handler/platform/baidu/types'
import { BianPageType } from '../../../lib/page_handler/platform/bian/types'
import { BingPageType } from '../../../lib/page_handler/platform/bing/types'
import { GiteePageType } from '../../../lib/page_handler/platform/gitee/types'
import { GooglePageType } from '../../../lib/page_handler/platform/google/types'
import { GreasyForkPageType } from '../../../lib/page_handler/platform/greasyfork/types'
import { IconfontPageType } from '../../../lib/page_handler/platform/iconfont/types'
import { SoPageType } from '../../../lib/page_handler/platform/so/types'
import { SogouPageType } from '../../../lib/page_handler/platform/sogou/types'
import { ZhiHuQuestionPageType } from '../../../lib/page_handler/platform/zhi_hu_question/types'
import { SUPPORTED_PLATFORMS } from '../../../types/constants'
import { EffectType, SYMBOLS } from '../../../types/interfaces'
import { AppModule } from '../types'

export function getAppearanceModules(pageType: PageType): ModulePlatformConfig {
  return {
    [AppModule.ThemeInherit.id]: {
      meta: {
        name: '主题继承',
        description: '未设置主题的页面自动继承其他页面的主题',
        category: 'appearance',
        icon: `${SYMBOLS.OTHERS.PALETTE}${SYMBOLS.USER.USER_GROUP}`,
        status: 'supported',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.ZHI_HU_QUESTION]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              ZhiHuQuestionPageType.Question,
              ZhiHuQuestionPageType.Answer,
            ]
            return supportPages.includes(pageType as ZhiHuQuestionPageType)
          },
        },
        [SUPPORTED_PLATFORMS.BILIBILI]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.BILIBILI_VIDEO]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.ICONFONT]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.BIAN]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              BianPageType.List,
              BianPageType.Detail,
            ]
            return supportPages.includes(pageType as BianPageType)
          },
        },
        [SUPPORTED_PLATFORMS.GITEE]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.GITHUB]: {
          status: 'not-needed',
        },
      },
    },
    [AppModule.ThemeSync.id]: {
      meta: {
        name: '主题同步',
        description: '全站主题统一，应用所有页面中最新的主题',
        category: 'appearance',
        icon: `${SYMBOLS.OTHERS.PALETTE}${SYMBOLS.OTHERS.MASK}`,
        status: 'supported',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.ZHI_HU_QUESTION]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              ZhiHuQuestionPageType.Question,
              ZhiHuQuestionPageType.Answer,
            ]
            return supportPages.includes(pageType as ZhiHuQuestionPageType)
          },
        },
        [SUPPORTED_PLATFORMS.BILIBILI]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.BILIBILI_VIDEO]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.ICONFONT]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.BIAN]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              BianPageType.List,
              BianPageType.Detail,
            ]
            return supportPages.includes(pageType as BianPageType)
          },
        },
        [SUPPORTED_PLATFORMS.GITEE]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.GITHUB]: {
          status: 'not-needed',
        },
      },
    },
    [AppModule.ThemeStyle.id]: {
      meta: {
        name: '主题样式',
        description: '应用内置主题样式',
        category: 'appearance',
        icon: `${SYMBOLS.OTHERS.PALETTE}${SYMBOLS.NATURE.RAINBOW}`,
        status: 'supported',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.ZHI_HU_QUESTION]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              ZhiHuQuestionPageType.Question,
              ZhiHuQuestionPageType.Answer,
            ]
            return supportPages.includes(pageType as ZhiHuQuestionPageType)
          },
        },
        [SUPPORTED_PLATFORMS.BILIBILI]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.BILIBILI_VIDEO]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.ICONFONT]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.BIAN]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              BianPageType.List,
              BianPageType.Detail,
            ]
            return supportPages.includes(pageType as BianPageType)
          },
        },
      },
    },
    [AppModule.AdEngine.id]: {
      meta: {
        name: '显示净化面板',
        description: '展示控制面板，可手动控制内置元素的显隐（固定于页面右下角位置）',
        category: 'appearance',
        icon: `${SYMBOLS.NETWORK.SHIELD}${SYMBOLS.OTHERS.VIEWED}`,
        status: 'supported',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.BILIBILI]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.BILIBILI_VIDEO]: {
          status: 'not-needed',
        },
        [SUPPORTED_PLATFORMS.GREASY_FORK]: {
          status: 'supported',
          defaultEnabled: false,
          pageTypeValidator: () => {
            const supportPages = [
              GreasyForkPageType.INDEX,
              GreasyForkPageType.SCRIPT_LIST,
              GreasyForkPageType.SCRIPT_VERSIONS,
              GreasyForkPageType.SCRIPT_FEEDBACK,
              GreasyForkPageType.SCRIPT_DISCUSSION,
              GreasyForkPageType.LIBRARIES,
              GreasyForkPageType.USERS,
              GreasyForkPageType.USER_PROFILE,
              GreasyForkPageType.DISCUSSIONS,
              GreasyForkPageType.DISCUSSIONS_DETAIL,
            ]
            return supportPages.includes(pageType as GreasyForkPageType)
          },
        },
        [SUPPORTED_PLATFORMS.BAI_DU]: {
          pageTypeValidator: () => {
            const notSupportPages = [
              BaiduPageType.NotFound,
            ]
            return !notSupportPages.includes(pageType as BaiduPageType)
          },
        },
        [SUPPORTED_PLATFORMS.GOOGLE]: {
          pageTypeValidator: () => {
            const notSupportPages = [
              GooglePageType.NotFound,
            ]
            return !notSupportPages.includes(pageType as GooglePageType)
          },
        },
        [SUPPORTED_PLATFORMS.SO_GOU]: {
          pageTypeValidator: () => {
            const notSupportPages = [
              SogouPageType.NotFound,
            ]
            return !notSupportPages.includes(pageType as SogouPageType)
          },
        },
        [SUPPORTED_PLATFORMS.ZHI_HU_QUESTION]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              ZhiHuQuestionPageType.Question,
              ZhiHuQuestionPageType.Answer,
            ]
            return supportPages.includes(pageType as ZhiHuQuestionPageType)
          },
        },
        [SUPPORTED_PLATFORMS.ICONFONT]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              IconfontPageType.Index,
            ]
            return supportPages.includes(pageType as IconfontPageType)
          },
        },
        [SUPPORTED_PLATFORMS.BIAN]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              BianPageType.List,
              BianPageType.Detail,
            ]
            return supportPages.includes(pageType as BianPageType)
          },
        },
      },
    },
    [AppModule.StyleEnhancement.id]: {
      meta: {
        name: '样式美化',
        description: '优化页面排版和视觉样式',
        category: 'appearance',
        icon: `${SYMBOLS.NATURE.SUNFLOWER}${SYMBOLS.OTHERS.PALETTE}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.CSDN]: {
          status: 'supported',
        },
        [SUPPORTED_PLATFORMS.ZHI_HU]: {
          status: 'supported',
        },
        [SUPPORTED_PLATFORMS.JUE_JIN]: {
          status: 'supported',
        },
        [SUPPORTED_PLATFORMS.BAI_DU]: {
          status: 'supported',
          pageTypeValidator: () => {
            const notSupportPages = [
              BaiduPageType.Index,
              BaiduPageType.Advanced,
              BaiduPageType.NotFound,
              BaiduPageType.Video,
              BaiduPageType.Note,
            ]
            return !notSupportPages.includes(pageType as BaiduPageType)
          },
        },
      },
    },
    [AppModule.ElementHider.id]: {
      meta: {
        name: '元素隐藏',
        description: '隐藏页面上的干扰元素',
        category: 'appearance',
        icon: `${SYMBOLS.NATURE.SUNFLOWER}${SYMBOLS.UI.EYE_OFF}`,
        status: 'supported',
        show: false,
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
    },
    [AppModule.BeautifyLink.id]: {
      meta: {
        name: '链接美化',
        description: '优化链接显示，鼠标悬浮后显示完整链接',
        category: 'appearance',
        icon: `${SYMBOLS.STATUS.LINK}${SYMBOLS.OTHERS.PALETTE}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.GREASY_FORK]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              GreasyForkPageType.SCRIPT_DISCUSSION,
              GreasyForkPageType.DISCUSSIONS_DETAIL,
            ]
            return supportPages.includes(pageType as GreasyForkPageType)
          },
        },
      },
    },
    [AppModule.HideSearchHistory.id]: {
      meta: {
        name: '隐藏历史',
        description: '隐藏搜索框中的历史记录',
        category: 'appearance',
        icon: `${SYMBOLS.UI.SEARCH}${SYMBOLS.UI.BLOCK_ALERT}`,
        status: 'not-needed',
        defaultEnabled: false,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.BAI_DU]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              BaiduPageType.Web,
              BaiduPageType.News,
              BaiduPageType.Index,
            ]
            return supportPages.includes(pageType as BaiduPageType)
          },
        },
        [SUPPORTED_PLATFORMS.GOOGLE]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              GooglePageType.Index,
              GooglePageType.IndexHk,
              GooglePageType.All,
              GooglePageType.Video,
              GooglePageType.ShortVideo,
              GooglePageType.Web,
            ]
            return supportPages.includes(pageType as GooglePageType)
          },
        },
        [SUPPORTED_PLATFORMS.BING]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              BingPageType.Web,
              BingPageType.Video,
              BingPageType.Academic,
              BingPageType.Dictionary,
              BingPageType.Index,
            ]
            return supportPages.includes(pageType as BingPageType)
          },
        },
        [SUPPORTED_PLATFORMS.SO_GOU]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              SogouPageType.Web,
              SogouPageType.Weixin,
              SogouPageType.Zhihu,
              SogouPageType.Medical,
              SogouPageType.Ask,
              SogouPageType.Encyclopedia,
              SogouPageType.News,
              SogouPageType.Knowledge,
              SogouPageType.IndexSearch,
              SogouPageType.IndexWeixin,
            ]
            return supportPages.includes(pageType as SogouPageType)
          },
        },
        [SUPPORTED_PLATFORMS.SO]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              SoPageType.Web,
              SoPageType.Video,
              SoPageType.News,
              SoPageType.Wenku,
              SoPageType.IndexSearch,
              SoPageType.IndexVideo,
              SoPageType.IndexWenku,
            ]
            return supportPages.includes(pageType as SoPageType)
          },
        },
      },
    },
    [AppModule.HideSearchSuggestions.id]: {
      meta: {
        name: '隐藏推荐',
        description: '在输入时自动隐藏搜索框下方的联想推荐列表，让输入更专注',
        category: 'appearance',
        icon: `${SYMBOLS.UI.SEARCH}${SYMBOLS.UI.BULLSEYE}`,
        status: 'not-needed',
        defaultEnabled: false,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.BAI_DU]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              BaiduPageType.Web,
              BaiduPageType.News,
              BaiduPageType.Note,
              BaiduPageType.Index,
            ]
            return supportPages.includes(pageType as BaiduPageType)
          },
        },
        [SUPPORTED_PLATFORMS.GOOGLE]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              GooglePageType.Index,
              GooglePageType.IndexHk,
              GooglePageType.All,
              GooglePageType.Video,
              GooglePageType.News,
              GooglePageType.ShortVideo,
              GooglePageType.Web,
              GooglePageType.Books,
            ]
            return supportPages.includes(pageType as GooglePageType)
          },
        },
        [SUPPORTED_PLATFORMS.BING]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              BingPageType.Web,
              BingPageType.Video,
              BingPageType.Academic,
              BingPageType.Dictionary,
              BingPageType.Index,
            ]
            return supportPages.includes(pageType as BingPageType)
          },
        },
        [SUPPORTED_PLATFORMS.SO_GOU]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              SogouPageType.Web,
              SogouPageType.Weixin,
              SogouPageType.Zhihu,
              SogouPageType.Video,
              SogouPageType.Medical,
              SogouPageType.Ask,
              SogouPageType.Encyclopedia,
              SogouPageType.News,
              SogouPageType.Knowledge,
              SogouPageType.IndexSearch,
              SogouPageType.IndexWeixin,
            ]
            return supportPages.includes(pageType as SogouPageType)
          },
        },
        [SUPPORTED_PLATFORMS.SO]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              SoPageType.Web,
              SoPageType.Video,
              SoPageType.News,
              SoPageType.Wenku,
              SoPageType.IndexSearch,
              SoPageType.IndexVideo,
              SoPageType.IndexWenku,
            ]
            return supportPages.includes(pageType as SoPageType)
          },
        },
      },
    },
    [AppModule.HideSearchHotLists.id]: {
      meta: {
        name: '隐藏热榜',
        description: '在输入时自动隐藏搜索框下方的热榜列表',
        category: 'appearance',
        icon: `${SYMBOLS.UI.SEARCH}${SYMBOLS.OTHERS.FIRE}`,
        status: 'not-needed',
        defaultEnabled: false,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.BING]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              BingPageType.Web,
              BingPageType.Video,
              BingPageType.Index,
            ]
            return supportPages.includes(pageType as BingPageType)
          },
        },
        [SUPPORTED_PLATFORMS.SO_GOU]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              SogouPageType.Web,
              SogouPageType.Video,
            ]
            return supportPages.includes(pageType as SogouPageType)
          },
        },
        [SUPPORTED_PLATFORMS.SO]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              SoPageType.News,
            ]
            return supportPages.includes(pageType as SoPageType)
          },
        },
      },
    },
    [AppModule.FileIcons.id]: {
      meta: {
        name: '文件图标',
        description: '为不同文件类型显示对应图标',
        category: 'appearance',
        icon: `${SYMBOLS.FILES.FOLDER}${SYMBOLS.OTHERS.VIEWED}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.GITEE]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              GiteePageType.Project,
              GiteePageType.HistoryProject,
              GiteePageType.CodeView,
            ]
            return supportPages.includes(pageType as GiteePageType)
          },
        },
      },
    },
    [AppModule.CommitIcons.id]: {
      meta: {
        name: '提交图标',
        description: '为不同提交类型显示对应图标',
        category: 'appearance',
        icon: `${SYMBOLS.UI.EDIT}${SYMBOLS.UI.TAG}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.GITEE]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              GiteePageType.Project,
              GiteePageType.HistoryProject,
              GiteePageType.Commits,
              GiteePageType.CodeView,
            ]
            return supportPages.includes(pageType as GiteePageType)
          },
        },
      },
    },
    [AppModule.DirTimeSimplifier.id]: {
      meta: {
        name: '目录时间简化',
        description: '仅显示最近更新目录的时间信息（默认最近1天）',
        category: 'appearance',
        icon: `${SYMBOLS.UI.EDIT}${SYMBOLS.TIME.CALENDAR}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.GITEE]: {
          status: 'supported',
          pageTypeValidator: () => {
            const supportPages = [
              GiteePageType.Project,
              GiteePageType.HistoryProject,
            ]
            return supportPages.includes(pageType as GiteePageType)
          },
        },
      },
    },
  }
}
